home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / applets / plot2d / g2d2.jav < prev    next >
Encoding:
Text File  |  1996-01-11  |  1.4 KB  |  59 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3. import java.net.URL;
  4.  
  5. public class g2d2 extends Applet {
  6.  
  7.       Graph2D graph;
  8.       Label title;
  9.       DataSet data1;
  10.       Axis    xaxis;
  11.       Axis    yaxis;
  12.  
  13.  
  14.       public void init() {
  15.         int i;
  16.         int j;
  17.  
  18.         graph = new Graph2D();
  19.  
  20.         graph.setFont(new Font("TimesRoman",Font.PLAIN,16));
  21.         
  22.         title = new Label(
  23.         "Spectrum of a giant elliptical Galaxy in the Virgo cluster",
  24.         Label.CENTER);
  25.  
  26.         title.setFont(new Font("TimesRoman",Font.PLAIN,16));
  27.  
  28.         setLayout( new BorderLayout() );
  29.         add("North",  title);
  30.         add("Center", graph);
  31.  
  32.  
  33.         try {
  34.         data1 = graph.loadFile(new URL(getDocumentBase(),"elliptical.data"));
  35.         } catch (Exception e) {
  36.           System.out.println("Failed to load data file!");
  37.         }
  38.  
  39.         data1.linecolor = new Color(255,255,0);
  40.  
  41.         xaxis = graph.createAxis(Axis.BOTTOM);
  42.         xaxis.attachDataSet(data1);
  43.         xaxis.title = new String("Wavelength (angstroms)");
  44.         xaxis.title_color = Color.magenta;
  45.  
  46.  
  47.         yaxis = graph.createAxis(Axis.LEFT);
  48.         yaxis.attachDataSet(data1);
  49.         yaxis.title = new String("Flux");
  50.         yaxis.title_color = Color.magenta; 
  51.  
  52.       }
  53.  
  54.       public void paint(Graphics g) {
  55.            graph.paint(g);
  56.       }
  57.  
  58. }
  59.